#pragma once

#ifndef _CMOBHANDLER_H_
#define _CMOBHANDLER_H_



class CChar;
class CNpc;
class CSpawnMobPool;

	struct familyRanks {
		unsigned short str;
		unsigned short dex;
		unsigned short vit;
		unsigned short agi;
		unsigned short inte;
		unsigned short mnd;
		unsigned short chr;
		unsigned short eva;
		unsigned short def;
	};


struct eInfo {
	unsigned int groupId;
	bool	isAlive;
};

struct mobIDPoolEntry  {
	int mobid;
	CNpc * pMob;
	__int64 tod;
	struct eInfo *pInfo;
};

struct mobPoolEntry {
	short	intid;
	char	name[30];
	char	lookDyn[20];
	int		lookMod;
	int		name_pre;
	int		flag;
	int		unknown;
	unsigned short	addsize;

	std::vector<mobIDPoolEntry*> idPool;

	familyRanks famRank;
	unsigned short familyId;
	unsigned int behaviour;
	bool isAgressive;
	unsigned short mobType;
	unsigned short mainJob;
	unsigned short subJob;
	unsigned short delay;
};

class CMobHandler
{
protected:
	static CMobHandler * _instance;
public:
	static CMobHandler * getInstance();
	CMobHandler();
	~CMobHandler();
	// temporary
	//std::vector<mobPoolEntry> m_mobPoolUnsorted;
	// one for each zone for direct access
	std::vector<mobPoolEntry*> m_mobPool[256];

	void loadMobPool();

	void tmpSpawn(int poolid, char * name, CChar * schar);

	void spawnMobScripted(char * name, struct position pos, unsigned char zone, unsigned int owner);

	// gets the next free id of a target, 0 if not existant
	unsigned int getAndAssignFreeId(int poolid, char * name, unsigned short zone, CNpc* npc );
	// frees an id
	void freeId(unsigned int mobid, char * name);
	void spawn(int poolid, mobIDPoolEntry * pPE, CSpawnMobPool * pSMP, struct SpawnPoint* pSP);

	mobIDPoolEntry * getNextMobId(mobPoolEntry * mPE, unsigned short respawnTime, unsigned int groupId , unsigned short maxSpawns);
	CSpawnMobPool * getSpawnMobPoolFromMobPool(mobPoolEntry * pMobPoolEntry, int zone);
};
#endif
